const { defineComponent,h} = require("vue");
import {List,PullRefresh,Loading} from "vant"
import {px_e_rem} from "@uit/common.js"

const PLists = defineComponent({
    data(){
        return{

        }
    },
    props:{
        load:{
            type:Function,
            required:false
        },
        refresh:{
            type:Function,
            required:false
        },
        Listarrts:{
            type:Object,
            required:false
        },
        nodata:{
            type:Boolean,
            required:false
        }
    },
    emits:['change','update:Listarrts'],
    setup(props, { attrs,slots,emit,watch }){
        const lists = slots.lists
        const pullingLoading = () => {
            return h(Loading,{color:'#3D39D8'},null)
        }
        const  Nodta = () =>{
            return h(
                'div',
                {style:{display:'flex',width:'100vw',height:px_e_rem(300),alignItems:'flex-end',justifyContent: 'center'}},
                [
                    h('img',{src:require('../../assets/imgs/nodata.png'),style:{width:px_e_rem(219),height:px_e_rem(172)}}),

                ]
            )
        }
        return ()  => h(
            PullRefresh,
            {   
                style:{
                    minHeight: 'calc(100vh - 120px)'
                },
                modelValue:props.Listarrts.refreshing,
                onRefresh:props.refresh,
                'onUpdate:modelValue':($event)=>emit('update:Listarrts',{refreshing:$event})
            },
            {
                default:() =>{
                    return  h(
                        'div',
                        {},
                        [
                            slots.title?slots.title():null,
                            h(
                                List,
                                {
                                    onLoad:props.load,
                                    loading:props.Listarrts.loading,
                                    finished:props.Listarrts.finished,
                                    finishedText:"No more",
                                    'onUpdate:loading':($event)=>emit('update:Listarrts',{loading:$event})
                                },
                                {
                                    default:()=>props.Listarrts.nodata?Nodta():lists(props.Listarrts)
                                }
                            )
                        ]
                    )
                },
                pulling:pullingLoading,
                loading:pullingLoading
            }
        )
    }
})

export default PLists